package com.poul.acfun.ac_presenter;

import com.poul.acfun.ac_model.AcBaseModel;
import com.poul.acfun.ac_view.AcBaseView;

import java.lang.ref.WeakReference;

/**
 * Created by poul on 2016/10/19.
 */

public abstract class AcBasePresenter<V extends AcBaseView,M extends AcBaseModel> {
    public M model;
    private WeakReference<V> weakReference;

    public AcBasePresenter() {
        model = createModel();
    }
    //绑定
    public void attach(V v){
        weakReference = new WeakReference<V>(v);
    }
    //解绑
    public void detach(){
        if (weakReference !=null){
            weakReference.clear();
            weakReference = null;
        }
    }

    public V getView(){
        if (weakReference != null){
            return weakReference.get();
        }
        return null;
    }

    protected abstract M createModel();


}
